﻿#include "guild_auction_timer.h"

#include "SendGuildAuctionStartMailNtfData_struct.h"

#include "guild/guild.h"
#include "time/service_time_scheduler.hpp"
#include "proxy/guild_service_timer_proxy_mgr.h"
#include "log/service_logger.hpp"

namespace guild_service {
bool GuildAuctionTimer::start() {
  handler_ = time_schedule(
      3000,
      [](std::uint64_t, std::time_t ms) -> bool {
        LOG_INFO("公会仓库拍卖开始");
        SendGuildAuctionStartMailNtfData data;
        data.item_list = {};
        GuildServiceTimerProxyMgrSingleton->ForeachProxy(
            [&data](const role_uuid_type role_uuid,
                    const std::shared_ptr<GuildClientTimerProxy> proxy_ptr) {
              proxy_ptr->SendGuildAuctionStartMailNtf(data);
            });
        return true;
      },
      0);

  return handler_ != kInvalidTimeHandler;
}


bool GuildAuctionTimer::stop() {
  if (handler_ == kInvalidTimeHandler) {
    return true;
  }
  if (!time_cancel(handler_)) {
    return false;
  }
  return true;
}

bool GuildAuctionTimer::started() const {
  // TODO timer_map check valid
  return handler_ != kInvalidTimeHandler;
}

GuildAuctionTimer::~GuildAuctionTimer() {
  stop();
}

} // namespace guild_service